package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class IntToByteArray {
	public static void main(String[] argv) {
		byte[] buf = new byte[]{0, 0, 0, 0, 0, 0, 0, 0};
		int offset = 2;
		int value = 2;
		write24BitIntToByteArray(buf, offset, value);
		System.out.println(Arrays.toString(buf));
	}


	private static void write24BitIntToByteArray(byte[] buf, int offset, int value) {
		buf[offset++] = (byte) (value & 0x000000ff);
		buf[offset++] = (byte) ((value & 0x0000ff00) >> 8);
		buf[offset] = (byte) ((value & 0x00ff0000) >> 16);
	}
}
